package control;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.service.TestService;
import model.vo.ProductVO;

import org.json.simple.JSONObject;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

public class AjaxController  extends MultiActionController{
	TestService testService;
	
	public void setTestService(TestService testService){
		this.testService=testService;
	}
	public void paging(HttpServletRequest request, HttpServletResponse response)
	throws Exception{
		int nowPage=1;
		JSONObject obj= new JSONObject();
		System.out.println("detail=="+request.getParameter("detail"));
		String detail=request.getParameter("detail");
		if(request.getParameter("number").equals('1')){
			nowPage=1;
		}else{
			nowPage = Integer.parseInt(request.getParameter("number"));
			System.out.println("cookie :"+nowPage);
		
		}
		ProductVO vo = new ProductVO();
		ModelAndView mv=new ModelAndView();
		if(detail.equals("par")){
		obj=testService.makepaging(nowPage,detail);
		}else if(detail.equals("dept")){
		obj=testService.makepaging(nowPage,detail);	
		}else if(detail.equals("com")){
		obj=testService.makepaging(nowPage,detail);	
		System.out.println("obj.complete");
		}
		System.out.println();
		PrintWriter out = response.getWriter();
		out.print(obj.toString());
		
		
		
	}
}
